package Thread.New.线程组;

@SuppressWarnings("all")
public class ThreadGounp_USE {
    public static void main(String[] args) {
        printGroupInfo(Thread.currentThread());
        //这个是把主线程也传递进去了
        Thread appThread = new Thread(new Runnable(){
            @Override
            public void run() {
                for (int i=0;i<5;i++) {
                    System.out.println("工作ing" + i);
                }
            }
        });
        appThread.setName("我的名字叫做a");
        appThread.start();
        //启动线程
        printGroupInfo(appThread);
    }

    static void printGroupInfo(Thread t) {
        ThreadGroup group = t.getThreadGroup();
        //获取 a线程的线程组
        System.out.println("线程的名字 -> " + t.getName() + " 线程组的名字为: "
                + group.getName()+ " 线程组中的最大优先级为: " + group.getMaxPriority()
                + " 线程组中活动的线程数目为: " + group.activeCount());

        ThreadGroup parent=group;
        do {
            ThreadGroup current = parent;
            parent = parent.getParent();
            if (parent == null) {
                break;
            }

            System.out.println(current.getName() + "该线程的父母为 " + parent.getName());
        } while (true);
        System.out.println("--------------------------");
    }
}
